# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=malcom
pkgver=708.02e55b9
pkgrel=6
pkgdesc="Analyze a system's network communication using graphical representations of network traffic."
groups=('blackarch' 'blackarch-networking' 'blackarch-defensive'
        'blackarch-malware')
url='https://github.com/tomchop/malcom'
arch=('any')
license=('custom:unknown')
depends=('python2' 'python2-virtualenv' 'python2-typing')
optdepends=('python2-celery')
makedepends=('git' 'python2-pip')
source=("git+https://github.com/tomchop/$pkgname.git")
sha512sums=('SKIP')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  find "$srcdir" -type f -name '*.py' | xargs sed -i \
    's|#!/usr/bin/env python|#!/usr/bin/env python2|'
  find "$srcdir" -type f -name '*.py' | xargs sed -i \
    's|#!/usr/bin/python|#!/usr/bin/env python2|'
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  install -Dm 644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
source venv/bin/activate
exec python2 $pkgname.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

